﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Pawn
{
    public partial class FrmCauHinh : Form
    {
        DataClassesDataContext db = new DataClassesDataContext();
        public FrmCauHinh()
        {
            InitializeComponent();
        }

        private void FrmCauHinh_Load(object sender, EventArgs e)
        {
            
            var query = from cd in db.CaiDats
                        select cd;
            foreach (CaiDat c in query)
            {
                tbDiaChi.Text = c.DiaChi;
                tbDienThoai.Text = c.DienThoai;
                tbTenCH.Text = c.TenCuaHang;
                tbTienTo.Text = c.TienToPhieu;
                tbHauTo.Text = c.HauToPhieu;
                tbLaiSuat.Value = (Int64)c.LaiSuat;
                tbMatKhau.Text = c.MatKhau;
            }
        }


        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (tbMatKhau.Text != tbXacNhan.Text)
            {
                MessageBox.Show("Xác nhận mật khẩu không khớp!", "Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            var query = from cd in db.CaiDats
                        select cd;
            foreach (var c in query)
            {
                c.DiaChi = tbDiaChi.Text;
                c.DienThoai = tbDienThoai.Text;
                c.TenCuaHang = tbTenCH.Text;
                c.TienToPhieu = tbTienTo.Text;
                c.HauToPhieu = tbHauTo.Text;
                c.LaiSuat = tbLaiSuat.Value;
                c.MatKhau = tbMatKhau.Text;
            }
            
            
            db.SubmitChanges();
            this.Close();
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
